﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kinect_NameSpace;
using System.Runtime.InteropServices;

namespace Kinect_COM
{
    /*
     * Constants for setting color stream size 
     */
    [Guid("cd4188e0-e4ee-4632-8a63-187988113671")]
    public class ColorStreamConstants
    {
        public const int COLOR_STREAM_RGB_640_480_30 = 1;
        public const int COLOR_STREAM_RGB_1280_960_12 = 2;
        public const int COLOR_STREAM_RGB_640_480_15 = 3;
        public const int COLOR_STREAM_IR_640_480_30 = 4;
    }

    /*
     * Constants for setting depth stream size 
     */
    [Guid("303738f2-c892-46e0-b20c-79dfcb2d1560")]
    public class DepthStreamConstants
    {
        public const int DEPTH_STREAM_640_480_30 = 1;
        public const int DEPTH_STREAM_320_240_30 = 2;
        public const int DEPTH_STREAM_80_60_30 = 3;
    }


    /*
     * Bit masks for enabling color, depth and skeleton stream
     */

    [Guid("a683301f-952b-4e1f-a7b5-a04359c35787")]
    public class StreamTypeConstants
    {
        public const byte BITMASK_COLOR = 0x1;
        public const byte BITMASK_DEPTH = 0x2;
        public const byte BITMASK_SKELETON = 0x3;
        public const byte BITMASK_INFRARED = 0x4;
    }

    [Guid("5EA021EE-9D66-4062-ACEF-3C404B75F000")]
    public interface Kinect_COMInterface
    {
        [DispId(1)]
        byte[] GetColorData();

        [DispId(2)]
        byte[] GetDepthData();

        [DispId(3)]
        void SetElevationAngle(int nAngle);

        [DispId(4)]
        void StartKinect(byte bStreamFlags);

        [DispId(5)]
        void StartKinect(byte bStreamFlags, int nColorStreamType, int nDepthStreamType);

        [DispId(6)]
        void StopKinect();

        [DispId(7)]
        int GetColorStreamWidth();

        [DispId(8)]
        int GetColorStreamHeight();

        [DispId(9)]
        int GetDepthStreamWidth();

        [DispId(10)]
        int GetDepthStreamHeight();
    }

    [Guid("1EF86609-CAC3-4dd8-B945-6D03C69A515F"),
    InterfaceType(ComInterfaceType.InterfaceIsIDispatch)]
    public interface Kinect_COMEvents
    {
    }

    [Guid("780D0B3C-B482-44fa-A30E-E08620E407DC"),
    ClassInterface(ClassInterfaceType.None),
    ComSourceInterfaces(typeof(Kinect_COMEvents))]
    public class KinectInterface : Kinect_COMInterface
    {
        public KinectController m_Controller = null;

        public KinectInterface()
        {
            m_Controller = new KinectController();
        }

        public void StartKinect(byte bStreamFlags)
        {
            m_Controller.StartKinect(bStreamFlags, 0, 0);
        }

        public void StartKinect(byte bStreamFlags, int colorStreamType, int depthStreamType)
        {
            m_Controller.StartKinect(bStreamFlags, colorStreamType, depthStreamType);
        }

        public void StopKinect()
        {
            m_Controller.StopKinect();
        }

        public void SetElevationAngle(int nAngle)
        {
            m_Controller.setElevationAngle(nAngle);
        }

        public byte[] GetColorData()
        {
            return m_Controller.getData(StreamType.Stream_Type_Color);
        }

        public byte[] GetDepthData()
        {
            return m_Controller.getData(StreamType.Stream_Type_Depth);
        }

        public int GetColorStreamWidth()
        {
            return m_Controller.getStreamWidth(StreamType.Stream_Type_Color);
        }

        public int GetColorStreamHeight()
        {
            return m_Controller.getStreamHeight(StreamType.Stream_Type_Color);
        }

        public int GetDepthStreamWidth()
        {
            return m_Controller.getStreamWidth(StreamType.Stream_Type_Depth);
        }

        public int GetDepthStreamHeight()
        {
            return m_Controller.getStreamHeight(StreamType.Stream_Type_Depth);
        }
    }
}
